home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / vecreg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  1.4 KB  |  58 lines

  1. /*
  2.  * vecreg.c -- arrow-shaped regions 
  3.  *
  4.  */
  5.  
  6. #include "reg.h"
  7. #include "display.h"
  8. #include "ui.h"
  9. #include "llist.h"
  10. #include "common.h"
  11. #include <X11/Xlib.h>
  12. #include <stdio.h>
  13. #include <math.h>
  14.  
  15. draw_vec(reg)
  16. struct region *reg;
  17. {
  18.   int ht=20, wid=15;
  19.   float   x, y, xb, yb, dx, dy, l, sina, cosa;
  20.   int     xc, yc, xd, yd,x1,y1,x2,y2;
  21.   XPoint pc,pd;
  22.   struct dlist *vec1, *vec2;
  23.  
  24.   
  25.   ras_line(reg->r_plist->pt, reg->r_plist->next->pt,
  26.        reg->r_dlist, orig_ximg, orig_img);
  27.   vec1=(struct dlist *) malloc(sizeof(struct dlist));
  28.   vec2=(struct dlist *) malloc(sizeof(struct dlist));
  29.   x1=reg->r_plist->pt.x;
  30.   y1=reg->r_plist->pt.y;
  31.   x2=reg->r_plist->next->pt.x;
  32.   y2=reg->r_plist->next->pt.y;
  33.   dx = x2 - x1;  dy = y1 - y2;
  34.   l = sqrt((double)(dx*dx + dy*dy));
  35.   if(l == 0)
  36.     return;
  37.   sina = dy / l;  cosa = dx / l;
  38.   xb = x2*cosa - y2*sina;
  39.   yb = x2*sina + y2*cosa;
  40.   x = xb - ht;
  41.   y = yb - wid / 2;
  42.   xc = x*cosa + y*sina + .5;
  43.   yc = -x*sina + y*cosa + .5;
  44.   y = yb + wid / 2;
  45.   xd = x*cosa + y*sina + .5;
  46.   yd = -x*sina + y*cosa + .5;
  47.   pc.x=xc;
  48.   pc.y=yc;
  49.   pd.x=xd;
  50.   pd.y=yd;
  51.   ras_line(pc,reg->r_plist->next->pt, vec1, orig_ximg, orig_img);
  52.   ras_line(pd,reg->r_plist->next->pt, vec2, orig_ximg, orig_img);
  53.   llist_add((llist *) vec1, (llist **) ®->r_dlist, (llist **) NULL);
  54.   llist_add((llist *) vec2, (llist **) ®->r_dlist, (llist **) NULL);
  55.  
  56.   draw_dlist(img_win->d_xid, reg->r_dlist);
  57. }
  58.